//
//  XHRSetAndHelpViewController.m
//  快医
//
//  Created by 胥鸿儒 on 16/7/6.
//
//

#import "XHRSetAndHelpViewController.h"
#import "SVProgressHUD.h"
#import "XHRFeedBackController.h"
#import "XHRLoginInfo.h"
#import "XHRPersonalMainPageViewController.h"
#import "JASidePanelController.h"

@interface XHRSetAndHelpViewController ()

@property (nonatomic, strong)NSArray *dataArr;

@end

@implementation XHRSetAndHelpViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.dataArr = @[@"意见与反馈",@"加号符号说明",@"修改密码",@"注销用户"];
    
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"setandhelp"];
    
    UIView *noUse = [UIView new];
    noUse.backgroundColor = [UIColor whiteColor];
    
    self.tableView.tableFooterView = noUse;
}


#pragma
#pragma mark -代理
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 4;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"setandhelp"];
    
    cell.textLabel.text = self.dataArr[indexPath.row];
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    // 当选第4行时注销
    if (indexPath.row == 3) {
        
        // 创建alert
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
        
        // 为alert添加2个按钮
        UIAlertAction *sure = [UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            // 在1秒后消失
            [SVProgressHUD setMinimumDismissTimeInterval:1];
            // 添加一个遮罩
            [SVProgressHUD showErrorWithStatus:@"注销"];
            // 整个后面的背景选择
            [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeBlack];
            
            [self performSelector:@selector(sel) withObject:nil afterDelay:1.1];
            
            // 将是否登录登录状态设置为未登录
            // 调用通知
            [[NSNotificationCenter defaultCenter]postNotificationName:@"cancle" object:nil];
            
            // 将偏好设置文件中的内容清空
            [XHRLoginInfo clearUserInfo];
        }];
        
        UIAlertAction *cancle = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:nil];
        
        [alert addAction:sure];
        [alert addAction:cancle];
        
        [self presentViewController:alert animated:YES completion:nil];
    }
    
    // MARK: 选择第一行的时候
    if (indexPath.row == 0){
        XHRFeedBackController *feedBack = [XHRFeedBackController new];
        
        [self.navigationController pushViewController:feedBack animated:YES];
    }
}

// 在遮罩完成后跳转到根控制器
- (void)sel{
     [self.navigationController popToRootViewControllerAnimated:YES];
}



@end
